package entities.axiom;

import java.util.HashSet;
import java.util.Set;

import entities.KBEntity;
import entities.concept.Concept;
import entities.concept.NotConcept;
import entities.concept.OrConcept;
import entities.concept.PConcept;

//import entities.vocabulary.KBVocabulary;

public class ConceptAxiom extends Axiom{

	protected Concept lhs;
	protected Concept rhs;

	public ConceptAxiom(Concept lhs, Concept rhs) {
		this.lhs = lhs;
		this.rhs = rhs;
	}

	public Concept getLHS() {
		return this.lhs;
	}

	public Concept getRHS() {
		return this.rhs;
	}

	public boolean LHSPrimitive() {
		return (this.lhs instanceof PConcept);
	}

	public boolean LHSBinarySimple() {
		return this.lhs.isBinarySimple();
	}

	// transform this axiom into ("well-formed") disjunctive items, e.g. top =>
	// {A, B}
	public static HashSet<Concept> axiomToDisjuncts(InclusionAxiom axiom) {
		HashSet<Concept> cons = new HashSet<Concept>();
		cons.add(axiom.getRHS());
		cons.add(new NotConcept(axiom.getLHS()));
		return Concept.reduceToDisjuncts(new OrConcept(cons));
	}

	public ConceptAxiom getPrimeCopy() {
		if (this instanceof InclusionAxiom) {
			// TODO: hack! these shouldn't be null
			if (this.getLHS() != null && this.getRHS() != null) {
				return new InclusionAxiom(this.getLHS().getPrimeCopy(), this
						.getRHS().getPrimeCopy());
			}
		} else if (this instanceof EquivalenceAxiom) {
			return new EquivalenceAxiom(this.getLHS().getPrimeCopy(), this
					.getRHS().getPrimeCopy());
		}
		// throw new Exception("Attempt to 'prime' Unrecognized Axiom Type.");
		return null;
	}

	@Override
	public Set<KBEntity> extractSig() {
		Set<KBEntity> sig =  new HashSet<KBEntity>();
		sig.addAll(this.lhs.extractSig());
		sig.addAll(this.rhs.extractSig());
		return sig;
	}

}
